package village.rainbow.slipin.database;

import village.rainbow.slipin.datamodel.DataRow;
import village.rainbow.slipin.datamodel.DataTable;
import android.content.Context;

public class DaoBase {

	public SqlMapClient _db;
	public Context _context;
	private String _xmlFileName;
	
	public DaoBase(Context context){
		this(context, "");
	}
	
	public DaoBase(Context context, String xmlFileName){
		_db = new SqlMapClient(context);
		_context = context;
		_xmlFileName = xmlFileName;
		
		try {
			_db.initDatabase();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public DataRow selectOne(String xmlId, DataRow bindParams) throws Exception{
		SqlSession session = SqlSession.openSession(_context, _xmlFileName);
		DataRow result;
		try{
			result = session.selectOne(xmlId, bindParams);
		}finally{
			session.close();
		}
		return result;
	}
	
	public DataTable selectList(String xmlId, DataRow bindParams) throws Exception{
		SqlSession session = SqlSession.openSession(_context, _xmlFileName);
		DataTable result;
		try{
			result = session.selectList(xmlId, bindParams);
		}finally{
			session.close();
		}
		return result;
	}
	
}
